const formatNum = (num) => {
  const curnum = String(num);
  if (!curnum.length) return '00';
  return curnum.length === 1 ? `0${curnum}` : curnum;
};
const formatTime = (timestamp, hasSecond = true) => {
  if (timestamp <= 0) return { hh: '00', mm: '00', ss: '00' };
  const seconds = timestamp;
  const hh = Math.floor(seconds / 3600);
  const mm = Math.floor((seconds - hh * 3600) / 60);
  const ss = seconds - hh * 3600 - mm * 60;
  const res = `${formatNum(hh)}:${formatNum(mm)}`;
  const sres = `:${formatNum(ss)}`;
  // console.log(hh,mm,timestamp,9999)
  return `${res}${hasSecond ? sres : ''}`;
};
const formatSearchDay = (timestamp) => {
  if (timestamp <= 0) return '';
  const DT = new Date(timestamp);
  const y = DT.getFullYear();
  const m = DT.getMonth();
  const d = DT.getDate();
  return `${y}${formatNum(m + 1)}${formatNum(d)}`;
};
const getSeconds = (serverTime) => {
  const DT = new Date(serverTime || '');
  const h = DT.getHours();
  const m = DT.getMinutes();
  const s = DT.getSeconds();
  // console.log(DT,serverTime,8888)
  return h * 60 * 60 + m * 60 + s;
};
const getTotalTime = (gapTime) => {
  const hh = Math.floor(gapTime / 3600);
  const mm = Math.floor((gapTime - hh * 3600) / 60);
  return `${hh}小时${mm}分钟`;
};
export default { formatTime, formatNum, getSeconds, getTotalTime, formatSearchDay };
